package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 化学品信息表(risk_chemicals)迁移脚本
 */
public class A003_RiskChemicalsMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A003_RiskChemicalsMigrationScript() {
        super(
            "risk_chemicals",
            "化学品信息数据迁移",
            "ra_chemicals",
            "risk_chemicals",
            3
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_chemicals (\n" +
               "    id,\n" +
               "    chemical_code,\n" +
               "    material_source_id,\n" +
               "    c_name,\n" +
               "    material_num,\n" +
               "    cas_num,\n" +
               "    chemical_use,\n" +
               "    tenant_id,\n" +
               "    is_system,\n" +
               "    is_del,\n" +
               "    create_time,\n" +
               "    create_by,\n" +
               "    update_time,\n" +
               "    update_by\n" +
               ")\n" +
               "SELECT\n" +
               "    id,\n" +
               "    chemical_code,\n" +
               "    material_source_id,\n" +
               "    c_name,\n" +
               "    material_num,\n" +
               "    cas_num,\n" +
               "    chemical_use,\n" +
               "    1 as tenant_id,\n" +
               "    is_system,\n" +
               "    is_del,\n" +
               "    DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s') AS create_time,\n" +
               "    1 AS create_by,\n" +
               "    DATE_FORMAT(update_time, '%Y-%m-%d %H:%i:%s') AS update_time,\n" +
               "    1 AS update_by\n" +
               "FROM risk_lunnan_test.ra_chemicals;";
    }

    /**
     * 获取源数据SQL
     *
     * @return 源数据查询SQL
     */
    public String getSourceSql() {
        return "SELECT\n" +
               "    id,\n" +
               "    chemical_code,\n" +
               "    material_source_id,\n" +
               "    c_name,\n" +
               "    material_num,\n" +
               "    cas_num,\n" +
               "    chemical_use,\n" +
               "    tenant_id,\n" +
               "    is_system,\n" +
               "    is_del,\n" +
               "    create_time,\n" +
               "    update_time\n" +
               "FROM risk_lunnan_test.ra_chemicals;";
    }

    /**
     * 获取目标数据SQL模板
     *
     * @return 目标数据SQL模板
     */
    public String getTargetSqlTemplate() {
        return "INSERT INTO risk_chemicals (\n" +
               "    id,\n" +
               "    chemical_code,\n" +
               "    material_source_id,\n" +
               "    c_name,\n" +
               "    material_num,\n" +
               "    cas_num,\n" +
               "    chemical_use,\n" +
               "    tenant_id,\n" +
               "    is_system,\n" +
               "    is_del,\n" +
               "    create_time,\n" +
               "    create_by,\n" +
               "    update_time,\n" +
               "    update_by\n" +
               ")";
    }
}
